Web / Basics / What is DOM and DOM tree ?
What is DOM?
-
Note
1. What is the DOM?
1. The Document Object Model (DOM) is a programming interface between all JavaScript code and the browser. Through DOM, we can make JavaScript to interact with the browser by creating, modifying, and deleting elements, setting styles, classes, and attributes, and listening and responding to events. 2. Who does create the DOM tree
2. The interaction between the DOM and the browser is essential for creating dynamic and interactive web pages.browser create the DOM tree from the html page
3. when does create the DOM treeWhen a web page is loaded, the browser creates a Document Object Model of the page.
4. why does create or for whatThe HTML DOM is programming interface for JavaScript. Javascript use the DOM tree to intract the web page
5. how does intract
1. Parsing HTML:When a web page is loaded, the browser parses the HTML document and constructs a DOM tree based on the HTML structure. This DOM tree represents the hierarchical structure of the document, with each HTML element represented as a node in the tree.
2. DOM API Access:JavaScript code running in the browser can access and manipulate this DOM tree using the DOM API. The DOM API provides a set of methods and properties that allow developers to interact with the DOM elements.
3. Element Selection::Developers can select specific elements in the DOM using methods like getElementById, getElementsByClassName, querySelector, querySelectorAll, etc. These methods return references to DOM elements that can be manipulated further.
4. Manipulation:Once a DOM element is selected, developers can modify its attributes, content, styles, and structure using the DOM API. For example, you can change the text content of an element, add or remove classes, update styles, append or remove child elements, etc.
5. Event Handling:The DOM API also allows developers to handle user interactions and events such as clicks, keypresses, form submissions, etc. Event listeners can be attached to DOM elements to trigger specific actions or functions when events occur.
Rendering Updates:As developers make changes to the DOM structure or content using the DOM API, the browser automatically updates the rendered web page to reflect these changes. This dynamic updating process ensures that the web page remains interactive and responsive to user actions.
1 .Directly Manipulates On-Screen Elements: Any changes made to the Real DOM immediately reflect on the user interface.
2. Slow Updates for Large Trees: When updating an element, the entire DOM tree needs to be re-rendered, which can be time-consuming, especially for complex applications.
3. Full Tree Re-Renders: Even minor changes require traversing the entire DOM tree, which affects performance.
MANVIA BLOG